package com.zzyl.nursing.service.impl;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.nursing.service.AIScore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class AIScoreImpl implements AIScore {

    @Value("${qianfan.accessKey}")
    private String accessKey;
    @Value("${qianfan.secretKey}")
    private String secretKey;
    @Value("${qianfan.model}")
    private String model;

    @Override
    public String scoreReport(String prompt) {
        try {
            ChatResponse response = new Qianfan(accessKey, secretKey)
                    .chatCompletion()
                    .addUserMessage(prompt)
                    .model(model)
                    .responseFormat("json_object")
                    .execute();

            String result = response.getResult();
            log.info("AI 返回结果: {}", result);
            return result;

        } catch (Exception e) {
            log.error("调用大模型失败", e);
            throw new RuntimeException("AI 调用异常", e);
        }
    }
}
